package jgcp.worker;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import jgcp.common.network.Connection;
import jgcp.config.Configuration;
import jgcp.worker.process.ExecutionThread;
import jgcp.worker.service.WorkerService;
/**
 * 
 * @Date 28/05/2009
 * @author Jie Zhao (288654)
 * @version 1.0
 */
public class Main {
	public static void main(String[] args) {
		try {
			String hostname = "127.0.0.1";
			if(args.length ==1)
			{
				hostname = args[0];
			}
			Socket s = new Socket(hostname,Configuration.getInstance().getServerPort());
			s.setKeepAlive(true);
			Connection c = new Connection();
			c.setSocket(s);
			WorkerService.initInstance(c);
			new WorkerMessageHandler(c).start();
			new ExecutionThread().start();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
